package ru.rchervot.sanasar.client.view;

import ru.rchervot.sanasar.client.event.EventSelectedSeveral;
import ru.rchervot.sanasar.client.event.HandlerSelectedSeveral;

import com.google.gwt.event.shared.HandlerManager;

public class SelectedSeveralPresenter implements Presenter {

	public interface Display extends Presenter.Display {
		void render(int numberOfSelectedItems);
	}
	
	protected final HandlerManager eventBus;
	protected final Display display;
	
	SelectedSeveralPresenter(Display display, HandlerManager eventBus) {
		this.display = display;
		this.eventBus = eventBus;
		
		listenForSelectedSeveral();
	}
	
	@Override
	public void bindDisplay() {
		display.setPresenter(this);
	}
	
	protected void listenForSelectedSeveral() {
		eventBus.addHandler(EventSelectedSeveral.getType(),
				new HandlerSelectedSeveral() {
			@Override
			public void onAction(
					EventSelectedSeveral event) {
				display.render(event.getNumberOfSelectedItems());
			}
		});
	}

}
